(commands popd)
;; TODO: write to output port
(define popd
  (lambda* (#:key
            ;; command interface
            (previous-result '())
            (shell-state default-shell-state)
            (silent #f))
    "Change the current working directory, poping the current working
directory off the directory stack."
    (let* ([dir-stack (get-shell-state shell-state 'directory-stack)]
           [updated-dir-stack (cdr dir-stack)])
      (let ([previous-working-directory (car updated-dir-stack)])
        (receive (new-pwd shell-state) (cd previous-working-directory #:silent #t)
          (values new-pwd
                  (update-shell-state* shell-state
                                       '(current-working-directory directory-stack)
                                       (list new-pwd updated-dir-stack))))))))


(alias pop-directory popd)
